# 引入线程池包
import threading
from concurrent.futures import ThreadPoolExecutor
import time

def crawl(url):
    msg = f'请求地址为：{url}'
    time.sleep(3)
    print(threading.current_thread().name)
    # print(msg)
    return msg;


if __name__ == '__main__':
    base_url = 'http://www.baidu.com?page={}'

    list1 = [base_url.format(i) for i in range(1, 6)]
    print('使用生成表达式生成列表：', list1)

    # 创建包含3条线程的线程池 # 使用with上下问管理器，就不用管如何关线程池了
    with ThreadPoolExecutor(3) as pool:
        for result in pool.map(crawl, list1):
            print(result)
